package com.redstar.interesting.main.config;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Component;

/**
 * @author lihongxing
 */
@Component
public class UsernameService implements com.tecdo.cpmsclient.pojo.GetUsername{
    @Override
    public String getUsername(Object principal) {
        if (principal instanceof OAuth2User){
            return ((OAuth2User) principal).getName();
        } else if (principal instanceof UserDetails) {
            return ((UserDetails)principal).getUsername();
        } else {
            return principal.toString();
        }
    }
}
